package com.gxuwz.check.action.admin;

import com.alibaba.fastjson.JSONObject;
import com.gxuwz.check.base.BaseAction;
import com.gxuwz.check.model.entity.SysCollegeEntity;
import com.gxuwz.check.service.admin.ICollegeService;
import com.gxuwz.check.util.PageBean;
import com.gxuwz.check.util.ResultJson;
import com.opensymphony.xwork2.ModelDriven;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class CollegeAction extends BaseAction implements ModelDriven<SysCollegeEntity> {
    private SysCollegeEntity sysCollegeEntity = new SysCollegeEntity();
    @Override
    public SysCollegeEntity getModel() {
        return sysCollegeEntity;
    }

    @Autowired
    private ICollegeService collegeService;

    private int page; //当前页码

    private String collegeName; //二级学院名字

    private Integer collegeId;

    /**
     * 获取所有二级学院
     */
    public void listCollege(){
        List<SysCollegeEntity> list = collegeService.listCollege(page);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        jsonObject.put("list",list);
        ResultJson.R(jsonObject);
    }

    /**
     * 删除二级学院
     */
    public void delete(){
        collegeService.delete(sysCollegeEntity.getCollegeId());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        ResultJson.R(jsonObject);
    }

    /**
     * 修改二级学院
     */
    public void edit(){
        collegeService.edit(sysCollegeEntity.getCollegeId(),sysCollegeEntity.getCollegeName());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        ResultJson.R(jsonObject);
    }

    /**
     * 添加二级学院
     */
    public void save(){
        collegeService.save(sysCollegeEntity.getCollegeName());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        ResultJson.R(jsonObject);
    }

    public void findCollegeById(){
        System.out.println("234234  "+collegeId);
        SysCollegeEntity sysCollegeEntity1 = collegeService.findCollegeById(sysCollegeEntity.getCollegeId());
        System.out.println("en  "+sysCollegeEntity);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        jsonObject.put("info",sysCollegeEntity1);
        ResultJson.R(jsonObject);
    }


    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public String getCollegeName() {
        return collegeName;
    }

    public void setCollegeName(String collegeName) {
        this.collegeName = collegeName;
    }

    public Integer getCollegeId() {
        return collegeId;
    }

    public void setCollegeId(Integer collegeId) {
        this.collegeId = collegeId;
    }
}
